package com.fc.advbox.job;

import com.fc.advbox.service.IEquipmentDailyProfitService;
import com.fc.advbox.service.IOrgAcctService;
import com.fc.advbox.service.IOrgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Configurable
@EnableScheduling
public class OrgProfitSettleTask {
    private static final Logger log = LoggerFactory.getLogger(OrgProfitSettleTask.class);

    @Autowired
    private IOrgAcctService orgAcctService;

    @Autowired
    private IEquipmentDailyProfitService equipmentDailyProfitService;

    //每天凌晨1点8分执行一次
    @Scheduled(cron = "0 8 1 ? * *")
    public void runDailyJobByCron() {
        log.info("Scheduling Tasks AgentDailySettle : start at: " + new Date());
        log.info("Starting ...");
        //DO SOMETHING
        equipmentDailyProfitService.calculateEquipmentDailyProfit(new Date());
        log.info("completed");
        log.info("Tasks AgentDailySettle: complete at: " + new Date());
    }



    //每月1号凌晨2点08分执行一次
    @Scheduled(cron = "0 8 2 1 * ?")
    public void runMonthJobByCron() {
        log.info("Scheduling Tasks AgentMonthSettle : start at: " + new Date());
        log.info("Starting ...");
        //DO SOMETHING
        orgAcctService.calculateOrgAccountProfit(new Date());
        log.info("completed");
        log.info("Tasks AgentMonthSettle: complete at: " + new Date());
    }

}
